using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ifstart : MonoBehaviour
{
    public GameObject Player;
    public GameObject Proper;
    // Start is called before the first frame update
    void Start()
    {
        
    }
    private void MapStart()
    {
        
        Player.GetComponent<PlayerInfo>().Goal = 0;
        PlayerInfo.state=PlayerInfo.NOW.Playing;
        Player.GetComponent<PlayerMove>().enabled = true;
        Player.GetComponent<PlayerInfo>().enabled = true;
        Player.GetComponent<PlayerFire>().enabled = true;
        
        Player.transform.position = new Vector3(0, -2, 7);

        GameObject.Find("CreateEmptys").GetComponent<CreateEmpty>().enabled = true;
        GameObject Go=GameObject.Find("CreateEmptys");
        Go.GetComponent<CreateEmpty>().create();
        print("22222");
        GameObject.Find("EndText").GetComponent<TMP_Text>().enabled = false;
        GameObject.Find("EndHelpText").GetComponent<TMP_Text>().enabled = false;
        GameObject.Find("StartText").GetComponent<TMP_Text>().enabled = false;
        GameObject.Find("HPText").GetComponent<TMP_Text>().enabled = true;
        print("33333");
        Instantiate(Proper, Vector3.zero, Quaternion.identity);
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            Application.Quit();
        }
        if (Input.GetKeyUp(KeyCode.Space))
        {
            
            Player.GetComponent<PlayerInfo>().enabled 
                = Player.GetComponent<PlayerMove>().enabled 
                = Player.GetComponent<PlayerFire>().enabled 
                = false;
            Player.transform.position = new Vector3(0, -6, 7);
            PlayerInfo.state = PlayerInfo.NOW.Waiting;
            GameObject[] gos = GameObject.FindGameObjectsWithTag("Empty");
            for (int i = 0; i < gos.Length; i++)
            {
                Destroy(gos[i].gameObject);

            }
            gos = GameObject.FindGameObjectsWithTag("EmptyBullet");
            for (int i = 0; i < gos.Length; i++)
            {
                Destroy(gos[i].gameObject);
            }

            GameObject go = GameObject.Find("EndText");
            go.GetComponent<TMP_Text>().text = "GAME OVER";
            go.GetComponent<TMP_Text>().enabled = true;
            go = GameObject.Find("EndHelpText");
            go.GetComponent<TMP_Text>().text = "Press the Enter key restarts the game ";
            go.GetComponent<TMP_Text>().enabled = true;
            go = GameObject.Find("HPText");
            go.GetComponent<TMP_Text>().enabled = false;

            Player.GetComponent<PlayerInfo>().HPIns();
            Destroy(GameObject.FindGameObjectWithTag("Prop"));
            Destroy(GameObject.FindGameObjectWithTag("CreateProp"));
            Player.GetComponent<PlayerInfo>().level = 1;
            return;
        }
        if (PlayerInfo.state == PlayerInfo.NOW.Waiting)
        {
            if (Input.GetKeyDown(KeyCode.Return))
            {
                MapStart();
            }
        }
    }
}
